package solutions;

import java.io.File;

public class DropSolution {

    public static void deleteFolder(String folderPath) {
        File folder = new File(folderPath);
        if (!folder.exists()) {
            System.out.println("Folder not found: " + folderPath);
            return;
        }

        if (folder.isDirectory()) {
            File[] files = folder.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.isDirectory()) {
                        // 递归删除子文件夹
                        deleteFolder(file.getAbsolutePath());
                    } else {
                        // 删除文件
                        file.delete();
                    }
                }
            }
        }
    }
    public static void DropDatabase(String rootpath,  String dbname) {
        File file =new File( rootpath+'/'+dbname);
        if(dbname == null || !file.exists())
        {
            System.out.println("no table ");
            return ;
        }
        deleteFolder(rootpath+'/'+dbname);
    }
    public static void DropTable(String rootpath, String dbname, String table) {
        File file =new File( rootpath+'/'+dbname+'/'+table);
        if(dbname == null || !file.exists())
        {
            System.out.println("no table ");
            return ;
        }
        deleteFolder(rootpath+'/'+dbname+'/'+table);
    }
}
